package com.sean.findme.search;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.app.ActivityGroup;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

import com.sean.findme.FmDBHelp;
import com.sean.findme.FmPositionHelp;
import com.sean.findme.R;
import com.sean.findme.dbentrys.XMLComm;
import com.sean.findme.near.NearActivity;

public class SearchZoneActivity extends Activity{
	
	private ListView mListView = null;
	private HashMap<String, String> premap = null;
	private ActivityGroup group = null;
	private ArrayList<XMLComm> list = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.search_zone);
		
		premap = SearchActivityManager.getInstance().getListActivityInfo().peek().getMap();
		
		group = (ActivityGroup)getParent();
		
		ArrayList<String> names = new ArrayList<String>();
		String city_key = FmDBHelp.getInstance(null, 0).commDBEntry.getKeyByName("city_tb", FmPositionHelp.getInstance().getM_strCurCity());
		list = FmDBHelp.getInstance(null, 0).commDBEntry.fetchAllRecordByTableWithKey("trade_zone_tb",city_key);
		if( list != null )
		{
			for( int i = 0; i < list.size(); i++ )
			{
				names.add(list.get(i).getUnknown1());
			}
		}
		
		mListView = (ListView)findViewById(R.id.search_zone_list);
		ArrayAdapter adapter = new ArrayAdapter(SearchZoneActivity.this,android.R.layout.simple_list_item_1,names);
		mListView.setAdapter(adapter);
		
		mListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int index,
					long arg3) {
				HashMap<String, String> map = new HashMap<String, String>();
				String title = getResources().getString(R.string.search_tab)+"-"+list.get(index).getUnknown1();
				map.put("title", title);
				map.put("position", list.get(index).getUnknown2());
				map.put("key", premap.get("text"));
				map.put("type", "2");
				
				SearchActivityManager.getInstance().JmpActivity(SearchZoneActivity.this, NearActivity.class, group, map, true);
				
			}
		});
		
	}
	
	

}
